package com.sjy.ylxt.controller;

import cn.dev33.satoken.annotation.SaCheckRole;
import cn.hutool.core.date.DateUtil;
import com.sjy.ylxt.entity.basic.ResultBody;
import com.sjy.ylxt.entity.dto.QueryReportsDTO;
import com.sjy.ylxt.service.YlxtReportsService;
import com.sjy.ylxt.utils.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigDecimal;

/**
 * @Author: 史俊颖
 * @CreateTime: 2024-12-12
 * @Description: 报告管理
 */
/**
 * 报告管理
 */
@RestController
@RequestMapping("/reports")
public class ReportsController {

    @Resource
    private YlxtReportsService ylxtReportsService;

    /**
     * 报告分页查询
     * @param pageNum
     * @param pageSize
     * @param reportType
     * @param reportDateStart
     * @param reportDateEnd
     * @param patientCount
     * @param appointmentCount
     * @param completedAppointmentCount
     * @param cancelledAppointmentCount
     * @param averageEvaluationScore
     * @param createUser
     * @param updateUser
     * @param deleteFlag
     * @return
     */
    @PostMapping("/page-list")
    public ResultBody<?> queryReports(
            @RequestParam(required = false, defaultValue = "1") Integer pageNum,
            @RequestParam(required = false, defaultValue = "10") Integer pageSize,
            @RequestParam(required = false) Integer reportType,
            @RequestParam(required = false) String reportDateStart,
            @RequestParam(required = false) String reportDateEnd,
            @RequestParam(required = false) Integer patientCount,
            @RequestParam(required = false) Integer appointmentCount,
            @RequestParam(required = false) Integer completedAppointmentCount,
            @RequestParam(required = false) Integer cancelledAppointmentCount,
            @RequestParam(required = false) BigDecimal averageEvaluationScore,
            @RequestParam(required = false) String createUser,
            @RequestParam(required = false) String updateUser,
            @RequestParam(required = false) Integer deleteFlag) {
        QueryReportsDTO dto = new QueryReportsDTO();
        dto.setPageNum(pageNum);
        dto.setPageSize(pageSize);
        dto.setReportType(reportType);
        if (StringUtils.isNotEmpty(reportDateStart)) {
            dto.setReportDateStart(DateUtil.parse(reportDateStart, "yyyy-MM-dd"));
        }
        if (StringUtils.isNotEmpty(reportDateEnd)) {
            dto.setReportDateEnd(DateUtil.parse(reportDateEnd, "yyyy-MM-dd"));
        }
        dto.setPatientCount(patientCount);
        dto.setAppointmentCount(appointmentCount);
        dto.setCompletedAppointmentCount(completedAppointmentCount);
        dto.setCancelledAppointmentCount(cancelledAppointmentCount);
        dto.setAverageEvaluationScore(averageEvaluationScore);
        dto.setCreateUser(createUser);
        dto.setUpdateUser(updateUser);
        dto.setDeleteFlag(deleteFlag);
        return ylxtReportsService.queryReports(dto);
    }
}
